#define _DEFAULT_SOURCE

#include "apue.h"
#include <stdlib.h>
#include <unistd.h>

int globval= 6; /* external variable in initialized data */

int main(void) {
    int var;    /* automatic variable on the stack */
    pid_t pid;

    var= 88;
    printf("before vfork\n");   /*we don't flush stdio*/
    if ((pid= vfork()) < 0) {
        err_sys("vfork error");
    } else if (pid == 0) {
        globval++;          /* child */
        var++;              
        fclose(stdout);
        exit(0);           /* child terminates */
    }

    /* parent continues here */
    if (printf("pid = %ld, glob = %d, var= %d\n", (long)getpid(), globval, var) == -1)
        err_sys("printf error");
}
